//
//  STDSSolidColorEffect.h
//  STDSRenderSDKIOS
//
//  Created by 陈学明 on 2023/4/21.
//

#ifndef STDSSolidColorEffect_h
#define STDSSolidColorEffect_h

#include "STDSBaseEffect.hpp"
#include <glm/gtc/type_ptr.hpp>

/// 色温效果
class STDSSolidColorEffect: public STDSBaseEffect {
public:
    STDSSolidColorEffect() {
        mEffectType = STDSEffectTypeSolidColor;
    }
    ~STDSSolidColorEffect() {
        
    }
public:

    void setColor(vec4 color) {
        mColor = color;
    }
    
    shared_ptr<STDSShaderProgram> getEffectProgram() {
        if (mTransformProgram == nullptr) {
            mTransformProgram = mContext->getProgram(kShaderSRCSolidColor);
        }
        return mTransformProgram;
    }
    
    void draw() override {
        auto program = getEffectProgram();
        if (program == nullptr) {
            return;
        }
        program->use();
        program->setUniform4f(program->getUniform("uColor"), mColor.x, mColor.y, mColor.z, mColor.w);
//        program->setMatrix(program->getUniform("uMatVex"), glm::value_ptr(mMatV));
//        program->setMatrix(program->getUniform("uMatTex"), glm::value_ptr(mMatT));
        
        mAtbRect.setPosVex(program->getAttrib("aPos"));
        mAtbRect.setPosTex(program->getAttrib("aTexCoord"));
        
        mAtbRect.draw();
        program->unuse();
    }

private:
    vec4 mColor{1.0};
    shared_ptr<STDSShaderProgram> mTransformProgram{nullptr};
};
#endif /* STDSSolidColorEffect_h */
